package pe.com.cotelasa.scp.entidad;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

@Entity
@Table(name = "ubigeo",catalog = "bdcotelasa", schema = "cotelasa")
@Cache(usage= CacheConcurrencyStrategy.READ_ONLY)
@NamedQueries({
    @NamedQuery(name = "Ubigeo.findAll", query = "SELECT u FROM Ubigeo u"),
    @NamedQuery(name = "Ubigeo.findById", query = "SELECT u FROM Ubigeo u WHERE u.id = :id"),
    @NamedQuery(name = "Ubigeo.findByCodigo", query = "SELECT u FROM Ubigeo u WHERE u.codigo = :codigo"),
    @NamedQuery(name = "Ubigeo.findByNombre", query = "SELECT u FROM Ubigeo u WHERE u.nombre = :nombre"),
    @NamedQuery(name = "Ubigeo.findByEstadoRegistro", query = "SELECT u FROM Ubigeo u WHERE u.estadoRegistro = :estadoRegistro"),
    @NamedQuery(name = "Ubigeo.findByUsrCreacion", query = "SELECT u FROM Ubigeo u WHERE u.usrCreacion = :usrCreacion"),
    @NamedQuery(name = "Ubigeo.findByFecCreacion", query = "SELECT u FROM Ubigeo u WHERE u.fecCreacion = :fecCreacion"),
    @NamedQuery(name = "Ubigeo.findByUsrModificacion", query = "SELECT u FROM Ubigeo u WHERE u.usrModificacion = :usrModificacion"),
    @NamedQuery(name = "Ubigeo.findByFecModificacion", query = "SELECT u FROM Ubigeo u WHERE u.fecModificacion = :fecModificacion")})
public class Ubigeo implements Serializable {
    
    @Basic(optional =     false)
    @Column(name = "fec_creacion")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecCreacion;
    @Column(name =     "fec_modificacion")
    @Temporal(TemporalType.TIMESTAMP)
    private Date fecModificacion;
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    
    @Basic(optional = false)
    @Column(name = "codigo")
    private String codigo;
    
    @Basic(optional = false)
    @Column(name = "nombre")
    private String nombre;
    
    @Basic(optional = false)
    @Column(name = "estado_registro")
    private char estadoRegistro;
    
    @Basic(optional = false)
    @Column(name = "usr_creacion")
    private String usrCreacion;
    
    @Column(name = "usr_modificacion")
    private String usrModificacion;
    
    @OneToMany(mappedBy = "idUbigeo", fetch = FetchType.LAZY)
    //@LazyCollection(LazyCollectionOption.TRUE)
    private Collection<Cliente> clienteCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idUbigeo", fetch = FetchType.LAZY)
    //@LazyCollection(LazyCollectionOption.TRUE)
    private Collection<Sede> sedeCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idUbigeo", fetch = FetchType.LAZY)
    //@LazyCollection(LazyCollectionOption.EXTRA) 
    private Collection<Empresa> empresaCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idUbigeo", fetch = FetchType.LAZY)
    //@LazyCollection(LazyCollectionOption.TRUE)
    private Collection<Proveedor> proveedorCollection;
    
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idUbigeo")
    private Collection<Courier> courierCollection;
    
    @JoinColumn(name = "id_pais", referencedColumnName = "id")
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Pais idPais;

    public Ubigeo() {
    	idPais = new Pais();
    }

    public Ubigeo(Integer id) {
        this.id = id;
    }

    public Ubigeo(Integer id, String codigo, String nombre, char estadoRegistro, String usrCreacion, Date fecCreacion) {
        this.id = id;
        this.codigo = codigo;
        this.nombre = nombre;
        this.estadoRegistro = estadoRegistro;
        this.usrCreacion = usrCreacion;
        this.fecCreacion = fecCreacion;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getCodigo() {
        return codigo;
    }

    public void setCodigo(String codigo) {
        this.codigo = codigo;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public char getEstadoRegistro() {
        return estadoRegistro;
    }

    public void setEstadoRegistro(char estadoRegistro) {
        this.estadoRegistro = estadoRegistro;
    }

    public String getUsrCreacion() {
        return usrCreacion;
    }

    public void setUsrCreacion(String usrCreacion) {
        this.usrCreacion = usrCreacion;
    }

    public Date getFecCreacion() {
        return fecCreacion;
    }

    public void setFecCreacion(Date fecCreacion) {
        this.fecCreacion = fecCreacion;
    }

    public String getUsrModificacion() {
        return usrModificacion;
    }

    public void setUsrModificacion(String usrModificacion) {
        this.usrModificacion = usrModificacion;
    }

    public Date getFecModificacion() {
        return fecModificacion;
    }

    public void setFecModificacion(Date fecModificacion) {
        this.fecModificacion = fecModificacion;
    }

    public Collection<Cliente> getClienteCollection() {
        return clienteCollection;
    }

    public void setClienteCollection(Collection<Cliente> clienteCollection) {
        this.clienteCollection = clienteCollection;
    }

    public Collection<Sede> getSedeCollection() {
        return sedeCollection;
    }

    public void setSedeCollection(Collection<Sede> sedeCollection) {
        this.sedeCollection = sedeCollection;
    }

    public Collection<Empresa> getEmpresaCollection() {
        return empresaCollection;
    }

    public void setEmpresaCollection(Collection<Empresa> empresaCollection) {
        this.empresaCollection = empresaCollection;
    }

    public Collection<Proveedor> getProveedorCollection() {
        return proveedorCollection;
    }

    public void setProveedorCollection(Collection<Proveedor> proveedorCollection) {
        this.proveedorCollection = proveedorCollection;
    }

    public Pais getIdPais() {
        return idPais;
    }

    public void setIdPais(Pais idPais) {
        this.idPais = idPais;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Ubigeo)) {
            return false;
        }
        Ubigeo other = (Ubigeo) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "pe.com.cotelasa.scp.entidad.Ubigeo[ id=" + id + " ]";
    }

    @XmlTransient
    public Collection<Courier> getCourierCollection() {
        return courierCollection;
    }

    public void setCourierCollection(Collection<Courier> courierCollection) {
        this.courierCollection = courierCollection;
    }

}
